#pragma once

#include <pthread.h>
#include <functional>

using func_t = std::function<void *()>;

class Thread
{
private:
    static void *Excute(void *args)
    {
        Thread *p = static_cast<Thread *>(args);
        p->_func();

        return nullptr;
    }

public:
    Thread(func_t task) : _isrunning(false), _func(task)
    {
    }

    void Start()
    {
        _isrunning = true;
        pthread_create(&_tid, nullptr, Excute, (void *)this);
    }

    void Join()
    {
        pthread_join(_tid, nullptr);
    }

    ~Thread()
    {
    }

private:
    pthread_t _tid;
    bool _isrunning;
    func_t _func;
};
